import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

import 'package:get/get.dart';

import '../controllers/dialog_controller.dart';

class DialogView extends GetView<DialogController> {
  void _showCupertinoDialog(BuildContext context) {
    showCupertinoDialog(
        builder: (BuildContext context) {
          return CupertinoAlertDialog(
            title: Text("title"),
            content: Text("message"),
            actions: [
              TextButton(
                  onPressed: () {
                    // Navigator.of(context).pop("cancel");
                    Get.back();
                  },
                  child: Text("取消"))
            ],
          );
        },
        context: context);
  }

  void _showAlertDialog(BuildContext context) {
    showDialog(
        context: context,
        builder: (BuildContext context) {
          return AlertDialog(
            title: Text("title"),
            content: Text("message"),
            actions: [TextButton(onPressed: () {}, child: Text("取消"))],
          );
        });
  }

  void _showAboutDialog(BuildContext context) {
    showAboutDialog(
        context: context,
        applicationName: "dialogName",
        applicationVersion: "1.0",
        applicationLegalese: "xxxxxx");
  }

  Widget _pressBuildDialog(String title, void Function() onTap) {
    return Container(
      height: 40,
      child: TextButton(
        child: Text(title),
        onPressed: onTap,
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('DialogView'),
        centerTitle: true,
      ),
      body: Center(
        child: Column(
          children: [
            _pressBuildDialog("_pressBuildAboutDialog", () {
              _showAboutDialog(context);
            }),
            _pressBuildDialog("dialog", () {
              _showAlertDialog(context);
            }),
            _pressBuildDialog("ios_dialog", () {
              _showCupertinoDialog(context);
            }),
            //强制 TextField 不可操作 IgnorePointer
            //AbsorbPointer
            AbsorbPointer(
              child: Container(
                child: TextField(
                  decoration: InputDecoration(
                    labelText: "input: ",
                    hintText: "input",
                  ),
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}
